/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CounterMenu.java
 *
 * Created on Oct 6, 2010, 5:27:54 PM
 */

package cat20032010;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.Timer;

/**
 *
 * @author Daniel Tan
 */
public class CounterMenu extends javax.swing.JFrame {
    Timer timer = new Timer (1000, new TimerListener());
    static String loginid="";
    static String password="";
    static NewOrder NewOrder = new NewOrder();
    static cashbillpanel cashbillpanel = new cashbillpanel();
    static Administrator Administrator = new Administrator();
    static AdminLogIn AdminLogIn = new AdminLogIn();
    static TableArrangement TableArrangement = new TableArrangement();
    
    /** Creates new form CounterMenu */
    public CounterMenu() {
        initComponents();
        setLocationRelativeTo(null);
        update();
        timer.start();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        current_time = new javax.swing.JTextField();
        date = new javax.swing.JTextField();
        AdminButton = new javax.swing.JToggleButton();
        BillButton = new javax.swing.JToggleButton();
        TableStatusButton = new javax.swing.JToggleButton();
        ServiceOption = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        ServicePanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setLayout(null);

        current_time.setEditable(false);
        current_time.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        current_time.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        current_time.setText("jTextField1");
        jPanel1.add(current_time);
        current_time.setBounds(10, 400, 100, 21);

        date.setEditable(false);
        date.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        date.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        date.setText("jTextField1");
        jPanel1.add(date);
        date.setBounds(10, 360, 100, 21);

        AdminButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/Admin.png"))); // NOI18N
        AdminButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/Adminselected.png"))); // NOI18N
        AdminButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/AdminPressed.png"))); // NOI18N
        AdminButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AdminButtonActionPerformed(evt);
            }
        });
        jPanel1.add(AdminButton);
        AdminButton.setBounds(10, 200, 114, 50);

        BillButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/Bill.png"))); // NOI18N
        BillButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/billpressed.png"))); // NOI18N
        BillButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/Billselected.png"))); // NOI18N
        BillButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/billpressed.png"))); // NOI18N
        BillButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BillButtonActionPerformed(evt);
            }
        });
        jPanel1.add(BillButton);
        BillButton.setBounds(10, 270, 114, 50);

        TableStatusButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/T_Status.png"))); // NOI18N
        TableStatusButton.setSelected(true);
        TableStatusButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/T_StatusPressed.png"))); // NOI18N
        TableStatusButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/T_Statuselected.png"))); // NOI18N
        TableStatusButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/T_StatusPressed.png"))); // NOI18N
        TableStatusButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TableStatusButtonMouseClicked(evt);
            }
        });
        TableStatusButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TableStatusButtonActionPerformed(evt);
            }
        });
        jPanel1.add(TableStatusButton);
        TableStatusButton.setBounds(10, 130, 114, 50);

        ServiceOption.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(153, 153, 153)));
        ServiceOption.setLayout(null);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/woodframe2.gif"))); // NOI18N
        ServiceOption.add(jLabel3);
        jLabel3.setBounds(4, -1, 730, 490);

        ServicePanel.setLayout(null);
        ServiceOption.add(ServicePanel);
        ServicePanel.setBounds(40, 40, 660, 410);
        ServicePanel.add(NewOrder);
        NewOrder.setBounds(10, 0, 690, 450);
        NewOrder.setVisible(false);

        ServicePanel.add(cashbillpanel);
        cashbillpanel.setBounds(10, 0, 690, 450);
        cashbillpanel.setVisible(false);

        ServicePanel.add(Administrator);
        Administrator.setBounds(10,0,690,450);
        Administrator.setVisible(false);

        ServicePanel.add(TableArrangement);
        TableArrangement.setBounds(15,0,690,450);
        TableArrangement.setVisible(true);

        jPanel1.add(ServiceOption);
        ServiceOption.setBounds(120, 120, 730, 490);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/Banner1.png"))); // NOI18N
        jPanel1.add(jLabel2);
        jLabel2.setBounds(80, 0, 800, 120);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Others/wood2.jpg"))); // NOI18N
        jPanel1.add(jLabel1);
        jLabel1.setBounds(0, 0, 900, 650);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CAT200-3-2010");
        setName("BaseFrame"); // NOI18N
        setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TableStatusButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TableStatusButtonMouseClicked
    }//GEN-LAST:event_TableStatusButtonMouseClicked

    private void TableStatusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TableStatusButtonActionPerformed
        TableStatusButton.setSelected(true);
        AdminButton.setSelected(false);
        BillButton.setSelected(false);
        cashbillpanel.setVisible(false);
        NewOrder.setVisible(false);
        Administrator.setVisible(false);
        TableArrangement.setVisible(true);
        AdminLogIn.setVisible(false);
        
    }//GEN-LAST:event_TableStatusButtonActionPerformed

    private void AdminButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AdminButtonActionPerformed
        AdminLogIn.reset();
        TableStatusButton.setSelected(false);
        BillButton.setSelected(false);
        AdminLogIn.setVisible(true);
        cashbillpanel.setVisible(false);
        NewOrder.setVisible(false);
        Administrator.setVisible(false);
        TableArrangement.setVisible(false);
        AdminButton.setSelected(true);
   //     this.setEnabled(false);
    }//GEN-LAST:event_AdminButtonActionPerformed

    private void BillButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BillButtonActionPerformed
        TableStatusButton.setSelected(false);
        AdminButton.setSelected(false);
        BillButton.setSelected(true);
        cashbillpanel.setVisible(true);
        NewOrder.setVisible(false);
        Administrator.setVisible(false);
        TableArrangement.setVisible(false);
        AdminLogIn.setVisible(false);

    }//GEN-LAST:event_BillButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CounterMenu().setVisible(true);
            }
        });
    }


    public void update() {
        Date currentDate = new Date();
        Date currentTime = new Date();

        time++;
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        SimpleDateFormat formattertime = new SimpleDateFormat("kk:mm:ss");
        String dateString = formatter.format(currentDate);
        String timeString = formattertime.format(currentTime);
        date.setText(dateString);
        current_time.setText(timeString);
        //JOptionPane.showMessageDialog(null, "test3");
    }
    public int time = 0;
    public Timer timer1;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton AdminButton;
    private javax.swing.JToggleButton BillButton;
    private javax.swing.JPanel ServiceOption;
    private javax.swing.JPanel ServicePanel;
    private javax.swing.JToggleButton TableStatusButton;
    private javax.swing.JTextField current_time;
    private javax.swing.JTextField date;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
private class TimerListener implements ActionListener{
	   public void actionPerformed(ActionEvent e){
		   update();
	   }
   }
}
